package com.twu.biblioteca;

/**
 * Created by mauricio on 10/1/14.
 */
public class Auth {

    private static User user = null;

    public static boolean authenticate(String libraryNumber, String password) {

        User user = User.getByLibraryNumber(libraryNumber);
        if(user != null) {
           if(user.getPassword().equals(password)) {
               login(user);
               return isLogged();
           }
        }
        clearSession();
        return false;
    }

    public static boolean isLogged() {
        return getLoggedUser() != null;
    }

    public static User getLoggedUser() {
        return user;
    }

    private static void login(User user) {
        Auth.user = user;
    }

    public static void clearSession() {
        user = null;
    }


}
